package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 处理请求和响应的方法
 *
 * @version V1.0
 * @package com.leyou.item.web
 * @description:
 * @author: pc
 * @date: 2019/6/23 17:14
 */

@RestController
@RequestMapping("category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    /**
     * 根据父节点查询商品类目
     *
     * @param pid
     * @return
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByParentId(@RequestParam(value = "pid", defaultValue = "0") Long pid) {
            List<CategoryDTO> list = categoryService.queryCategoryByParentId(pid);
            return ResponseEntity.ok(list);
    }

    //根据商品分类id，查询商品分类

    @GetMapping("list")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByIds(@RequestParam("ids") List<Long> ids) {
        List<CategoryDTO> list = categoryService. queryCategoryByIds(ids);
        return  ResponseEntity.ok(list);
    }
}
